package com.ning.weixin.controller;

import com.github.pagehelper.PageInfo;
import com.ning.weixin.service.UserInfoService;
import com.ning.weixin.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Api(description = "积分排名")
@RestController
@RequestMapping("/njxs/rank")
public class ScoreRankController {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation("排行榜")
    @RequestMapping(value = "scoreRank", method = RequestMethod.GET)
    public PageInfo scoreRank(HttpServletRequest request,
                       @ApiParam(name = "pageNum", value = "页数", required = false)
                       @RequestParam(name = "pageNum", required = false, defaultValue = "1") int pageNum,
                       @ApiParam(name = "pageSize", value = "每页数量", required = false)
                       @RequestParam(name = "pageSize", required = false, defaultValue = "10") int pageSize) {
        PageInfo<Map<String, Object>> rank = userInfoService.getScoreRank(pageNum, pageSize);
        request.setAttribute("rank", rank);
        return rank;
    }

}
